/**
 * Created by zzl on 2016/5/5.
 */
$(document).ready(function(){
    var $user_name =document.getElementsByClassName('cas');
    var $price =document.getElementsByClassName('val');
    var $reg = /^(([0-9]{0,9})|([0-9]{0,9} +\.[0-9]{1,2})|([0-9]{0,9} +\.[0-9]{1,2}[￥]))$/;
    var $subMit = document.getElementsByClassName('cet');
    for (var i = 0, j = $subMit.length; i < j; i++){
        //scope2 作用域2
        var $set = $subMit[i];
        $set.onclick = function(i){
            //scope3 作用域3
            return function(){
                //scope4 作用域4
                console.log(i);
                var e=i;
                if ( e<$user_name.length){
                    var $key = $user_name[i];
                    if($key.value ==''){
                        layer.alert('请填写服务项目名称', {
                            icon: 2,
                            shade: 0.2
                        });
                        return false;
                    }
                    else if($key.value !=''&& $key.value.length >7 ){
                        layer.alert('服务项目名称不能超过7个字', {
                            icon: 2,
                            shade: 0.2
                        });
                        return false;
                    }
                    var $val = $price[i];
                    if($val.value ==''){
                        layer.alert('请输入价格', {
                            icon: 2,
                            shade: 0.2
                        });
                        return false;
                    }
                    else  if($val.value !='' && !$reg.test($val.value)){
                        layer.alert('价格不能超过9位数', {
                            icon: 2,
                            shade: 0.2
                        });
                        return false;
                    }
                }
            }
        }(i)
    }
});

function checkAddConfig(){
    var $user_name =$('#key1').val();
    if($user_name ==''){
        layer.alert('请填写服务项目名称', {
            icon: 2,
            shade: 0.2
        });
        return false;
    }
    else if( $user_name !='' && $user_name.length >7 ){
        layer.alert('服务项目名称不能超过7个字', {
            icon: 2,
            shade: 0.2
        });
        return false;

    }
    console.log($user_name);
    var $val =document.getElementById('val1');
    var $reg = /^(([0-9]{0,9})|([0-9]{0,9} +\.[0-9]{1,2})|([0-9]{0,9} +\.[0-9]{1,2}[￥]))$/;
    if($val.value ==''){
        layer.alert('请输入价格', {
            icon: 2,
            shade: 0.2
        });
        return false;
    }
    else if($val.value !='' && !$reg.test($val.value) ){
        layer.alert('价格不能超过9位数', {
            icon: 2,
            shade: 0.2
        });
        return false;
    }
}